<template>
  <div class="doctor">
    <div class="doctor-content-head">
      <nuxt-link to="/doctor">
        <div
          class="doctor-content-head-text"
        >
          医生
        </div>
      </nuxt-link>
      <div class="doctor-content-head-icon" />
      <div class="doctor-content-head-detils-text">
        医生主页
      </div>
    </div>
    <div class="doctor-wrap">
      <div class="doctor-content">
        <Doctor :doctor-data="doctorData" />
        <div class="doctor-content-project-wrap">
          <div class="doctor-content-project-head">
            <div
              class="doctor-content-project-text"
              :class="{'active':active==='推荐项目'}"
              @click="tab('项目')"
            >
              推荐项目
            </div>
            <div
              v-if="caseNum"
              class="doctor-content-case"
              :class="{'active':active==='真人案例'}"
              @click="tab('案例')"
            >
              真人案例 ({{ caseNum }})
            </div>
          </div>
          <div
            v-if="active==='推荐项目'"
          >
            <div v-if="projectData.length" class="doctore-content-project-item-wrap">
              <div
                v-for="item in projectData"
                :key="item.product_id"
                class="doctore-content-project-item"
              >
                <ProjectList :project-data="item" />
              </div>
            </div>
            <div
              v-if="projectData.length===0"
              class="doctore-noData"
            >
              <div class="doctore-noData-content">
                <img
                  src="~assets/img/no-date.png"
                  alt=""
                >
                <div class="doctore-noData-content-text">
                  这里什么都没有~
                </div>
              </div>
            </div>
          </div>
          <div
            v-if="active==='真人案例'"
            class="doctore-content-case-item-wrap"
          >
            <DiaryList :diary-data="diaryData" />
          </div>
        </div>
      </div>
      <div class="doctor-hospital">
        <div class="doctor-hospital-title">
          <div class="doctor-hospital-title-text">
            所属医院
          </div>
          <nuxt-link :to="`/hospital/${doctorData.hospital.user_id}`">
            <div class="doctor-hospital-title-See">
              <div class="doctor-hospital-title-See-text">
                查看
              </div>
              <div class="doctor-hospital-title-See-icon" />
            </div>
          </nuxt-link>
        </div>
        <div class="doctor-hospital-content">
          <nuxt-link :to="`/hospital/${doctorData.hospital.user_id}`">
            <img
              :src="doctorData.hospital.user_photo"
              class="doctor-hospital-photo"
            >
          </nuxt-link>
          <nuxt-link :to="`/hospital/${doctorData.hospital.user_id}`">
            <div
              class="doctor-hospital-content-data"
            >
              <div class="doctor-hospital-content-data-title">
                {{ doctorData.hospital.user_name }}
              </div>
              <div class="doctor-hospital-content-data-stars">
                <div
                  v-if="doctorData.hospital.evaluation_record_stat!==null"
                  class="doctor-hospital-content-data-stars"
                >
                  <Stars :value="doctorData.hospital.evaluation_record_stat.records[0].record_value" /> {{ doctorData.hospital.evaluation_record_stat.records[0].record_value }}.0
                </div>
                <div
                  v-else
                  class="doctor-hospital-content-data-stars"
                >
                  <Stars :value="5" /> 5.0
                </div>
              </div>
              <div class="doctor-hospital-content-data-num">
                {{ doctorData.hospital.user_statistic.case }}个案例 | {{ doctorData.hospital.user_statistic.place_total }}个预约
              </div>
              <div class="doctor-hospital-content-data-address">
                地址:{{ doctorData.hospital.user_attributes.user_address }}
              </div>
            </div>
          </nuxt-link>
          <div class="doctor-hospital-content-authentication" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getDoctorData, getProjectRecommendData, getdiaryData } from '@/api/doctorDetails'
import { disYears } from '@/utils/util'
import Stars from '@/components/stars'
import DiaryList from '@/components/diaryList'
import ProjectList from '@/components/doctorProjectList'
import Doctor from '@/components/productDoctor'
export default {
  components: {
    ProjectList,
    Stars,
    DiaryList,
    Doctor
  },
  async asyncData({ isDev, route, store, env, params, query, req, res, redirect, error }) {
    const [doctorData, projectData, diaryData] = await Promise.all([
      getDoctorData(params.details).then(res => {
        return res.data
      }),
      getProjectRecommendData(params.details, 500).then(res => {
        return res.data
      }),
      getdiaryData(params.details, 500).then(res => {
        return res.data
      })
    ])
    return {
      doctorData,
      projectData,
      diaryData
    }
  },
  data() {
    return {
      disYears,
      active: '推荐项目',
      caseNum: 0
    }
  },
  computed: {

  },
  created() {
    this.caseNum = this.diaryData.length
  },
  mounted() {

  },
  methods: {
    tab(val) {
      if (val === '案例') {
        this.active = '真人案例'
      } else {
        this.active = '推荐项目'
      }
    }
  },
  head() {
    // console.log(this.doctorData)
    const conword = []
    this.doctorData.user_attributes.good_at.forEach(item => {
      conword.push(item.name)
    })
    return {
      title: `【${this.doctorData.user_name}】医生_${this.doctorData.hospital.user_name}医院_预约挂号_整形案例_容猫医美`,
      meta: [
        { hid: 'description',
          name: 'description',
          content: `${this.doctorData.user_name}医生在${this.doctorData.hospital.user_name}医院，擅长明星项目:${conword},在容猫医美${this.doctorData.user_name}
          医生个人主页，您可以查看${this.doctorData.user_name}医生的整形项目，整形文章等，促进您对${this.doctorData.user_name}医生的进一步了解。`
        }, {
          name: 'keywords', content: `${this.doctorData.user_name} ,${this.doctorData.hospital.user_name}医院 `
        }, {
          'http-equiv': 'mobile-agent', content: 'format=html5', url: `https://m.rongcat.com/doctor/${this.$route.params.details}`
        }
      ]
    }
  }
}
</script>
<style scoped lang="scss">
.doctor {
  width: 100%;
  background: rgba(246, 246, 246, 1);
  .doctor-wrap {
    width: 1190px;
    margin: 0 auto;
    padding-bottom: 30px;
    overflow: hidden;
    display: flex;
  }
}
.doctor-content-head {
  width: 1190px;
  height: 54px;
  display: flex;
  align-items: center;
  margin: 0 auto;
  padding-top: 8px;
}
.doctor-content-head-text {
  font-size: 14px;
  font-weight: 400;
  color: rgba(51, 51, 51, 1);
  line-height: 20px;
  margin-left: 30px;
}
.doctor-content-head-text:hover {
  cursor: pointer;
}
.doctor-content-head-detils-text {
  font-size: 14px;
  font-weight: 400;
  color: rgba(80, 76, 255, 1);
  line-height: 20px;
}
.doctor-content-head-icon {
  width: 4px;
  height: 8px;
  background: url("~assets/img/right-icon.png") center center no-repeat;
  background-size: 100% 100%;
  margin-left: 10px;
  margin-right: 10px;
}
.doctor-content {
  width: 840px;
  border-radius: 4px;
  background: #fff;
}
.doctor-hospital {
  width: 340px;
  height: 152px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  margin-top: 0px;
  margin-left: 10px;
  .doctor-hospital-title {
    width: 100%;
    height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(240, 240, 240, 1);
    .doctor-hospital-title-text {
      margin-left: 16px;
      font-size: 16px;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      line-height: 22px;
    }
    .doctor-hospital-title-See:hover{
      cursor: pointer;
    }
    .doctor-hospital-title-See {
      display: flex;
      font-size: 16px;
      font-weight: 600;
      color: rgba(216, 216, 216, 1);
      line-height: 22px;
      align-items: center;
      margin-right: 19px;
      .doctor-hospital-title-See-icon {
        width: 8px;
        height: 8px;
        background: url("~assets/img/more-icon.png") center center no-repeat;
        background-size: 100% 100%;
        margin-left: 4px;
      }
    }
  }
  .doctor-hospital-content {
    margin-top: 13px;
    display: flex;
    justify-content: space-between;
  }
  .doctor-hospital-photo:hover{
    cursor: pointer;
  }
  .doctor-hospital-photo {
    width: 72px;
    height: 72px;
    margin-left: 13px;
  }
  .doctor-hospital-content-data:hover {
    cursor: pointer;
  }
  .doctor-hospital-content-data {
    width: 194px;
    .doctor-hospital-content-data-title {
      width: 194px;
      font-size: 15px;
      font-weight: 500;
      color: rgba(51, 51, 51, 1);
      line-height: 21px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .doctor-hospital-content-data-stars {
      display: flex;
      font-size: 12px;
      font-weight: 400;
      color: rgba(153, 153, 153, 1);
      line-height: 17px;
      align-items: center;
    }
    .doctor-hospital-content-data-num {
      font-size: 11px;
      font-weight: 400;
      color: rgba(153, 153, 153, 1);
      line-height: 16px;
    }
    .doctor-hospital-content-data-address {
      width: 194px;
      font-size: 11px;
      font-weight: 400;
      color: rgba(153, 153, 153, 1);
      line-height: 16px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .doctor-hospital-content-authentication {
    width: 51px;
  }
}
.doctor-content-project-wrap {
  margin-top: 20px;
  .doctor-content-project-head {
    width: 100%;
    height: 48px;
    border-top: 1px solid rgba(246, 246, 246, 1);
    border-bottom: 1px solid rgba(246, 246, 246, 1);
    display: flex;
    align-items: center;
  }
  .doctor-content-project-text {
    width: 112px;
    height: 50px;
    border-right: 1px solid rgba(246, 246, 246, 1);
    text-align: center;
    font-size: 14px;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    line-height: 50px;
  }
  .doctor-content-project-text:hover {
    cursor: pointer;
  }
  .active {
    color: rgba(80, 76, 255, 1);
  }
}
.doctor-content-case {
  width: 112px;
  height: 50px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(51, 51, 51, 1);
  line-height: 50px;
  text-align: center;
}
.doctor-content-case:hover {
  cursor: pointer;
}
.doctore-content-project-item-wrap {
  display: flex;
  flex-wrap: wrap;
  padding: 10px;
  .doctore-content-project-item {
    margin-right: 7px;
  }
}
.doctore-content-case-item-wrap {
  margin-top: 20px;
  margin-left: 20px;
}
.doctore-noData {
  width: 840px;
  height: 790px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  margin-top: 10px;
  position: relative;
  .doctore-noData-content {
    width: 242px;
    height: 210px;
    position: absolute;
    left: 50%;
    top:150px;
    margin-left: -121px;
    > img {
      width: 242px;
      height: 191px;
    }
    .doctore-noData-content-text{
      font-size:14px;
      font-family:PingFangSC-Regular,PingFang SC;
      font-weight:400;
      color:rgba(153,153,153,1);
      line-height:20px;
      text-align: center;
    }
  }
}
</style>
